
#include <stdio.h>
#include <IoLexer.h>
#include <IoNumber.h>
#include <IoToken.h>
#include <IoList.h>

char *slurp(FILE *fp) {
    int len;
    char *content;

    fseek(fp, 0L, SEEK_END);  /* Position to end of file */
    len = ftell(fp);     /* Get file length */
    rewind(fp);               /* Back to start of file */
    
    content = calloc(len+1, sizeof(char));

    fread(content, len, 1, fp);
    content[len] = '\0';
    return content;
}

int main(int argc, char**argv) {
    FILE *fp;
    IoLexer *lexer;
    char *text;

    fp = fopen(argv[1], "r");
    
    text = slurp(fp);

    fclose(fp);
    //text="foo\nbar\n123.4";

    lexer = IoLexer_new();

	IoLexer_string_(lexer, text);

	IoLexer_lex(lexer);

    IoToken *t;

    while((t = IoLexer_pop(lexer))) {
        printf("{%s} %s\n", 
               IoToken_typeName(t), 
               IoToken_name(t));
    }

	IoLexer_free(lexer);
    free(text);
}
